*-------------------------------------------------------------------------------*
* DIRECTORIES
*-------------------------------------------------------------------------------*
local l_direc_data `1'
local l_direc_code `2' 
local l_direc_figtab `3' 

local direc_data_raw  `l_direc_data'/raw
local direc_data_clean `l_direc_data'/clean



*-------------------------------------------------------------------------------*
* 
*-------------------------------------------------------------------------------*
eststo clear
foreach l_aggperc in 025 050 075 100 {
	
	use "`direc_data_clean'/mjt_regready_agg`l_aggperc'.dta", clear

	keep if year >= 1985 & journal_nlmid != "8303128"
	
	nois di ""
	nois di ""
	nois di ""
	nois di ""
	nois di ""
	nois di "`l_aggperc'"
					
	foreach l_var of varlist eshr2_frcnt_all jshr_frcnt_all {
		gen A_`l_var' = `l_var'>0
		ihstrans `l_var'
	}
	
	* JM MT
	qui {
		reghdfe ihs_jshr_frcnt_all ihs_eshr2_frcnt_all , a(fe_jm fe_mt) 
		local l_r2tot = e(r2)
		reghdfe ihs_jshr_frcnt_all ihs_eshr2_frcnt_all , a(fe_mt) 
			local estflg_semipar2_jm = `l_r2tot'-`e(r2)'
			local estflg_par2_jm = (`l_r2tot'-`e(r2)')/(1-`e(r2)')
		reghdfe ihs_jshr_frcnt_all ihs_eshr2_frcnt_all , a(fe_jm) 
			local estflg_semipar2_mt = `l_r2tot'-`e(r2)'
			local estflg_par2_mt = (`l_r2tot'-`e(r2)')/(1-`e(r2)')
		reghdfe ihs_jshr_frcnt_all , a( fe_jm fe_mt)
			local estflg_semipar2_X = `l_r2tot'-`e(r2)'
			local estflg_par2_X = (`l_r2tot'-`e(r2)')/(1-`e(r2)')
	}
	eststo: reghdfe ihs_jshr_frcnt_all ihs_eshr2_frcnt_all , a(fe_jt fe_jm fe_mt) cluster(fe_m)
		local l_r2tot = e(r2)
		estadd scalar estflg_r2tot = `l_r2tot'
		estadd scalar estflg_semipar2_jm = `estflg_semipar2_jm'
		estadd scalar estflg_par2_jm = `estflg_par2_jm'
		estadd scalar estflg_semipar2_mt = `estflg_semipar2_mt'
		estadd scalar estflg_par2_mt = `estflg_par2_mt'
		estadd scalar estflg_semipar2_X = `estflg_semipar2_X'
		estadd scalar estflg_par2_X = `estflg_par2_X'
		tabstat jshr_frcnt_all eshr2_frcnt_all if e(sample), save
		estadd scalar estflg_elast = (_b[ihs_eshr2_frcnt_all]*(sqrt((r(StatTotal)[1,1])^2+1)/r(StatTotal)[1,1])*(r(StatTotal)[1,2]/sqrt((r(StatTotal)[1,2])^2+1)))
	
			
}
esttab using "`l_direc_figtab'/tab_agg.tex", keep(ihs_eshr2_frcnt_all) label mlabels(none) ///
	b(%5.3fc) se(%5.3fc) star(* 0.1 ** 0.05 *** 0.01) ///
	scalars(estflg_elast estflg_r2tot estflg_par2_jm estflg_par2_mt estflg_par2_X ) ///
	sfmt(%5.3fc %5.3fc %5.3fc %5.3fc %5.3fc) nonotes ///
	style(tex) substitute(_ \_  $  \\$  %  \% ) ///
	replace
	
eststo clear
